package cn.tedu.cwfw.ser.service.impl;

import cn.tedu.cwfw.ser.mapper.SerMapper;
import cn.tedu.cwfw.ser.pojo.dto.SerSaveParam;
import cn.tedu.cwfw.ser.pojo.entity.Ser;
import cn.tedu.cwfw.ser.pojo.vo.SerVO;
import cn.tedu.cwfw.ser.service.SerService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

@Service
@Slf4j
public class SerServiceImpl implements SerService {
    @Autowired
    SerMapper serMapper;

    @Override
    public void insert(SerSaveParam serSaveParam) {
        log.debug("添加服务信息:{}", serSaveParam);
        Ser ser = new Ser();
        BeanUtils.copyProperties(serSaveParam, ser);
        serMapper.insert(ser);
        log.debug("添加服务信息成功");
    }

    @Override
    public List<SerVO> findByType(Long serviceType) {
        log.debug("根据服务类型查询服务信息:{}", serviceType);
        List<SerVO> serVOS = serMapper.findByType(serviceType);
        return serVOS;
    }

    @Override
    public SerVO findById(Long id) {
        log.debug("根据id查询服务信息:{}", id);
        SerVO serVO = serMapper.findById(id);
        return serVO;
    }

    @Override
    public void update(SerSaveParam serSaveParam) {
        log.debug("修改服务信息:{}", serSaveParam);
        Ser ser = new Ser();
        BeanUtils.copyProperties(serSaveParam, ser);
        serMapper.update(ser);
        log.debug("修改服务信息成功");
    }

    @Override
    public void delete(Long id) {
        log.debug("删除服务信息:{}", id);
        serMapper.delete(id);
        log.debug("删除服务信息成功");
    }
}
